<?php
/**
 * 后台管理员控制器(登录\修改密码\注销等)
 */
class AdminController extends PlatformController
{
    /**
     * 展示登录页
     */
    public function loginAction()
    {
        $this->display('login.html');
    }
    /**
     * 验证登录信息合法性
     */
    public function checkAction()
    {
    	$admin_name=$this->escapeData($_POST['admin_name']);
    	$admin_pass=$this->escapeData($_POST['admin_pass']);
    	$passcode=$this->escapeData($_POST['passcode']);
    	$catpcha=Factory::M('Catpcha');
    	if(!$catpcha->checkCatpcha($passcode))
    	{
    		$this->jump('index.php?p=Back&c=Admin&a=login',':(验证码错误');
    	}
    	/**
    	 * 创建Model,验证合法性
    	 */
    	$admin=Factory::M('AdminModel');
    	$result=$admin->check($admin_name,$admin_pass);
    	if($result)
    	{
    		@session_start();
    		$_SESSION['adminInfo']=$result;
    		// var_dump($_SESSION['adminInfo']);die;
    		$admin=$admin->updateAdminInfo($result['admin_id']);
    		echo '成功';
    		$this->jump('index.php?p=Back&c=Manage&a=index');
    	}
    	else
    	{
    		$this->jump('index.php?p=Back&c=Admin&a=login',':(用户名或密码错误');
    	}

    }
    public function catpchaAction()
    {
    	$catpcha = Factory::M('Catpcha');
    	$catpcha->generate();
    }
     public function logoutAction()
    {
		@session_start();
		unset($_SESSION['adminInfo']);
		session_destroy();
		$this->jump('index.php?p=Back&c=Admin&a=login');
    }
}